package com.system.outpatientsystem.service.impl;

import com.system.outpatientsystem.mapper.UserMapper;
import com.system.outpatientsystem.pojo.User;
import com.system.outpatientsystem.service.UserService;
import com.system.outpatientsystem.utils.MD5Utils;
import com.system.outpatientsystem.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findById(Integer id){
        return userMapper.findById(id);
    }

    @Override
    public void register(User u) {
        //加密密码
//        String md5String = MD5Utils.MD5Upper(u.getPassword());
//        u.setPassword(md5String);
        //添加
        userMapper.add(u);
        System.out.println("添加成功");
    }

    @Override
    public User findByPhone(String phone) {
        return userMapper.findByPhone(phone);
    }

    @Override
    public void userUpdate(User user) {
        userMapper.userUpdate(user);
    }

    @Override
    public void userUpdatePwd(String new_pwd) {
        Map<String, Object> map = ThreadLocalUtil.get();
        String phone = (String) map.get("phone");
        userMapper.userUpdatePwd(MD5Utils.MD5Upper(new_pwd),phone);
    }
}
